package com.bailiban.controller;

import com.bailiban.service.Cov19Service;
import com.bailiban.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhulang
 * @Classname CovController
 * @Description TODO
 * @Date 2020/3/20 21:47
 */
@RequestMapping("/refresh")
@RestController
@Api(tags = "数据爬取更新")
public class CovController {
    @Autowired
    private Cov19Service cov19Service;

    @RequestMapping("/save")
    @ApiOperation(value = "数据保存",notes = "保存每天的数据",httpMethod = "GET")
    public Result save() {
        //更新的数据都是最新一天的数据
        //只需要月日，不需要年份
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd");
        String date = dateFormat.format(new Date());
        return cov19Service.updateCovData(date);
    }
}
